<template>
  <el-card>
    <el-input
      v-model="page.input"
      placeholder="请输入内容进行查询"
      :clearable="true"
      style="width: 30%; float: left; margin-bottom: 10px"
    ></el-input>

    <el-button
      type="primary"
      @click="loadCollection()"
      style="width: 5%; float: left; margin-left: 10px"
      ><i class="el-icon-search"></i
    ></el-button>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="collectionGrade" label="催收等级" width="140">
      </el-table-column>
      <el-table-column prop="collectionWay" label="催收方式" width="140">
      </el-table-column>
      <el-table-column prop="userName" label="被催收人"> </el-table-column>
      <el-table-column prop="staffId" label="执行员工"> </el-table-column>
      <el-table-column prop="collectionBy1" label="执行时间"> </el-table-column>
      <el-table-column prop="collectionBy2" label="结束时间"> </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="primary" @click="handleEdit(scope.row.borrowId)"
            >编辑</el-button
          >
          <el-button
            type="warning"
            style="width: 70px"
            @click="handlEnd(scope.row.collectionId)"
            >归档</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page.currentPage"
      :page-sizes="pageInfo.pageSizes"
      :page-size="page.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageInfo.total"
    >
    </el-pagination>
    <!-- ------------------------删除模态框---------------------------- -->
    <el-dialog title="修改" :visible.sync="dialog.deleteShow" width="40%">
      <span>确定要归档吗</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialog.deleteShow = false">取 消</el-button>
        <el-button type="primary" @click="handlupdate()">确 定</el-button>
      </span>
    </el-dialog>
  </el-card>
</template>

<script>
export default {
  data() {
    return {
      page: {
        currentPage: 1,
        pagesize: 5,
        input: "",
      },
      pageInfo: {
        total: 0,
        pageSizes: [5, 20, 30, 50, 100],
      },
      tableData: {},
      selectCollection: {},
      dialog: {
        deleteShow: false,
      },
    };
  },
  methods: {
    handlEnd(id) {
      this.dialog.deleteShow = true;
      this.$axios.get("/Collection/" + id).then((res) => {
        this.selectCollection = res.data.data.collection;
      });
    },

    handlupdate() {
      this.dialog.deleteShow = false;
      this.$axios.put("/Collection", this.selectCollection).then((res) => {
        this.$message.success("归档成功");
      });
      this.selectCollection = "";
      this.loadCollection();
    },

    loadCollection() {
      this.$axios.post("/Collection/page", this.page).then((res) => {
        this.tableData = res.data.data.list;
        this.pageInfo.total = res.data.data.pageInfo;
      });
    },
    //当每页显示条数改变时
    handleSizeChange(size) {
      this.page.pagesize = size;
      this.loadCollection();
    },
    //当页数改变时
    handleCurrentChange(currentPage) {
      this.page.currentPage = currentPage;
      this.loadCollection();
    },
  },
  mounted() {
    this.loadCollection();
  },
};
</script>